package de.justphil.tcg.tcgserver.game.mechanics.property.properties;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import de.justphil.tcg.tcgserver.game.mechanics.game.Game;
import de.justphil.tcg.tcgserver.game.mechanics.property.Property;

public class PoisonDefensLoss extends Property {

	public PoisonDefensLoss(Game game) {

		super(game);
	}
	
	private boolean lock = false;

	@Override
	public int getDefenseModification() {

		/*
		 * Using a lock to avoid a loop.
		 */
		if (!lock) {

			lock = true;
			int result = -this.getMonster().getDefense();
			lock = false;

			return result;

		} else {

			return 0;
		}
	}

	@Override
	public int getType() {

		return PROPERTY_POISON_DEFENSE_LOSS;
	}
	
	@Override
	public void writeData(Game game, DataOutput out) throws IOException {

		super.writeData(game, out);
		
		out.writeBoolean(lock);
	}
	
	@Override
	public void readData(Game game, DataInput in) throws IOException {

		super.readData(game, in);

		lock = in.readBoolean();
	}
	
	@Override
	protected int[] getCounterProperties() {

		return new int[]{PROPERTY_POISON_RESISTANT};
	}
}
